package com.huawei.saas.listener;

import com.huawei.saas.properties.TenantProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.event.RefreshListener;
import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.stereotype.Component;

/**
 * @program: config-jdbc-demo
 * @author: GuoGaoJu
 * @create: 2023-04-11
 **/
@Slf4j
@Component
public class PropertiesRefreshListener extends RefreshListener {


    @Autowired
    private TenantProperties tenantProperties;

    private ContextRefresher contextRefresher;
    public PropertiesRefreshListener(ContextRefresher contextRefresher) {
        super(contextRefresher);
        this.contextRefresher=contextRefresher;
    }

    //刷新前删除map，防止已删除的路由配置仍存在
    @Override
    public void onApplicationEvent(RefreshRemoteApplicationEvent event) {
        tenantProperties.setTenantMap(null);
    }
}




